package com.gxa.meiye.admin.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.gxa.meiye.admin.service.FileUpLoadService;
import com.gxa.meiye.core.common.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@Api(tags = "图片上传模块")
@RestController
@RequestMapping("/mlsupload")
public class FileUpLoad {
    @Autowired
    FileUpLoadService fileUpLoadService;
    @ApiOperation(value = "头像上传",notes = "上传头像接口")
    @PostMapping ("/images")
    public JsonResult upload(@RequestPart MultipartFile multipartFile ) throws JsonProcessingException {
        System.out.println(multipartFile);
        System.out.println("-------------------------");
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        if(multipartFile.isEmpty()){
            jsonResult.setMsg("文件为空");
        }else {
            String upload = fileUpLoadService.upload(multipartFile);
            jsonResult.setMsg("上传成功");
            jsonResult.setData(upload);
        }
        return jsonResult;
    }
}
